package com.zjitc.Redis;

import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Single;
import com.zjitc.dao.UsersDao;
import com.zjitc.po.User;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/10 14:36
 * @description:
 */

@Component
public class Redis {

  @Autowired
  private Jedis jedis;

  public Redis(UsersDao usersDao){
    jedis =new Jedis();
    List<User> list =usersDao.findAll();
    final String key_sex_m="key_sex_M";
    final String key_age_larger_45 ="key_age_larger_45";
    list.forEach((item) ->{
      if (item.getAge() >=45){
        jedis.sadd(key_age_larger_45,Integer.toString(item.getId()));
      }
      if (item.getSex().equals("M")){
        jedis.sadd(key_sex_m, String.valueOf(item.getId()));
      }
    });
    Set<String> strings =jedis.sinter(key_sex_m,key_age_larger_45);
    System.out.println(strings);
  }
}
